package cz.muni.fi.pb138.mathml_canonicalizator;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

/**
 *
 * @author ndru
 */
public class CopyTransformer implements Transformer {
    
    private Node root;
    
    CopyTransformer(String tagName, Map<String, String> attributes,
            Map<String, List<String>> properties){
        
        List<String> attr_del = properties.get("attr_del") != null ?
                properties.get("attr_del") : new ArrayList<String>();
        
        // removes all attributes specified in attr_del
        Collection<String> c = attributes.keySet();
        Iterator it = c.iterator();
        while (it.hasNext()) {
            if (attr_del.contains((String) it.next())) {
                it.remove();
            }
        }
        
        root = new NodeImpl(tagName, attributes);
    }

    @Override
    public void addChild(Node n) {
        root.addChild(n);
    }

    @Override
    public Node transform() {
        return root;
    }

    @Override
    public void setTextContent(String s) {
        root.setTextContent(s);
    }
}
